var stylesheets    = require('../stylesheet-config.js')
var gulp          = require('gulp')
var minify        = require('gulp-minify-css')
var handleErrors  = require('../lib/handleErrors')
var gulpIf        = require('gulp-if')
var path          = require('path')
var changed       = require('gulp-changed')
var concat        = require('gulp-concat')
var notify        = require('gulp-notify')
var rename        = require('gulp-rename')
var argv          = require('yargs').argv;
  


global.cssTaskObj = {};
for (var i in stylesheets.module) {
  global.cssTaskObj['css_'+i] = cssTask(stylesheets.module[i]);
}


function cssTask(moduleName){
  return function() {
    if (argv.prod) {
      var dev = true;
    }
    return gulp.src(moduleName.paths)
      .pipe(changed(moduleName.exportPath))
      .pipe(concat(moduleName.contactName))
      .pipe(rename({ suffix: '.min' }))
      .pipe(gulpIf(dev, minify()))
      .pipe(gulp.dest(moduleName.exportPath))
      .pipe(notify({ message: stylesheets.message}))
  };
}

global.cssTaskNameArray = [];
for (var j in global.cssTaskObj) {
  global.cssTaskNameArray.push(j)
  gulp.task(j, global.cssTaskObj[j])
}

module.exports = global.cssTaskObj;

